/**
 * 
 */
package com.ms.player;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.google.gson.Gson;
import com.xpec.c4.game.utility.GameUtility;

/**
 * h5 agent 回傳資料時用的參數
 * 
 * @author TW15010
 */
public class AgentData {
	/** log4j object */
	private static final Log log = LogFactory.getLog(AgentData.class);

	// 固定不會變的欄位 ========================================

	private String openid;
	private String ezname;
	private String domain;
	private String parent;
	
	// 登入時會更新的欄位 ======================================

	private String callbackUrl;
	private String coinType;

	// =======================================================

	/**
	 * 轉成 json 字串
	 * 
	 * @return
	 */
	public String toJson() {
		Gson gson = new Gson();
		String json = gson.toJson(this);
		return json;
	}

	/**
	 * 把 json 轉回資料實體
	 * 
	 * @param json
	 * @return
	 */
	public static AgentData parse(String json) {
		if (!GameUtility.isHaveString(json)) {
			return null;
		}

		Gson gson = new Gson();
		AgentData data = null;
		try {
			data = gson.fromJson(json, AgentData.class);
		} catch (Exception e) {
			if (log.isErrorEnabled()) {
				log.error("parse json fail, json=" + json, e);
			}
			return null;
		}

		return data;
	}
	
	/**
	 * 取得營運商 id, 為了方便存取, 減少搞混機會增加的 getter
	 * @return
	 */
	public String getVenderId() {
		return parent;
	}

	/**
	 * 取得子營運商 id, 為了方便存取, 減少搞混機會增加的 getter
	 * @return
	 */
	public String getSubVenderId() {
		return ezname;
	}

	public String getOpenid() {
		return openid;
	}

	public void setOpenid(String openid) {
		this.openid = openid;
	}

	public String getEzname() {
		return ezname;
	}

	public void setEzname(String ezname) {
		this.ezname = ezname;
	}

	public String getParent() {
		return parent;
	}

	public void setParent(String parent) {
		this.parent = parent;
	}

	public String getCallbackUrl() {
		return callbackUrl;
	}

	public void setCallbackUrl(String callbackUrl) {
		this.callbackUrl = callbackUrl;
	}

	public String getDomain() {
		return domain;
	}

	public void setDomain(String domain) {
		this.domain = domain;
	}

	public String getCoinType() {
		return coinType;
	}

	public void setCoinType(String coinType) {
		this.coinType = coinType;
	}
}
